package de.uni.muenster.idw2.xml;

import java.io.IOException;
import java.io.StringWriter;

import org.xmlpull.v1.XmlSerializer;

import android.util.Xml;
import de.uni.muenster.idw2.data.BoundingBox;

public class BBRequestWriter {

	public static String getXML(BoundingBox bb){
		XmlSerializer serializer = Xml.newSerializer();
		StringWriter writer = new StringWriter();
		
		try {
			serializer.setOutput(writer);
			serializer.startDocument("UTF-8", true);
			
			serializer.startTag("", "buildingsbbox");
			
			serializer.attribute("", "lon_bottom_left", Double.toString(bb.getLon_bottom_left()));
			serializer.attribute("", "lat_bottom_left", Double.toString(bb.getLat_bottom_left()));
			serializer.attribute("", "lon_top_right", Double.toString(bb.getLon_top_right()));
			serializer.attribute("", "lat_top_right", Double.toString(bb.getLat_top_right()));
			
			serializer.endTag("", "buildingsbbox");
			
			serializer.endDocument();
			
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		return writer.toString();
	}
}
